package com.warm.pump.module.sys.controller;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.MyBeanUtils;
import com.warm.pump.frame.gen.util.OutJson;
import com.warm.pump.module.sys.bean.po.gen.DictGroup;
import com.warm.pump.module.sys.service.IDictGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 *  sys_dict_group
 *
 */
@Controller
@RequestMapping("/dictGroup")
public class DictGroupController {
	@Autowired
	private IDictGroupService dictGroupService;
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("dictGroup:list")
	public OutJson list(Integer page, Integer limit, DictGroup dictGroup){
		Map<String, Object> map = new HashMap<>();
		MyBeanUtils.copyBean2Map(map,dictGroup);
       //查询列表数据
        PageBean pageBean = dictGroupService.getPageBeanByMap(map, page, limit);

		return OutJson.ok().put("page", pageBean);
	}


	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("dictGroup:info")
	public OutJson info(@PathVariable("id") Long  id){
		DictGroup dictGroup = dictGroupService.queryObject(id);
		
		return OutJson.ok().put("dictGroup", dictGroup);
	}


	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("dictGroup:save")
	public OutJson save(@RequestBody DictGroup dictGroup){
		dictGroup.setStatusTime(new Date());
		dictGroupService.save(dictGroup);
		
		return OutJson.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("dictGroup:update")
	public OutJson update(@RequestBody DictGroup dictGroup){
		dictGroup.setStatusTime(new Date());
		dictGroupService.update(dictGroup);
		
		return OutJson.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("dictGroup:delete")
	public OutJson delete(@RequestBody Long [] ids){
		dictGroupService.deleteBatch(ids);
		
		return OutJson.ok();
	}
	
}
